package com.lxmes.device.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lxmes.common.annotation.Log;
import com.lxmes.common.core.controller.BaseController;
import com.lxmes.common.core.domain.AjaxResult;
import com.lxmes.common.enums.BusinessType;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.lxmes.device.domain.FwMaintenancePrice;
import com.lxmes.device.service.IFwMaintenancePriceService;
import com.lxmes.common.utils.poi.ExcelUtil;
import com.lxmes.common.core.page.TableDataInfo;

/**
 * 维保价目Controller
 * 
 * @author zhangzhiyu
 * @date 2023-05-11
 */
@Api(tags = "维保价目")    
@RestController
@RequestMapping("/device/fwMaintenancePrice")
public class FwMaintenancePriceController extends BaseController
{
    @Autowired
    private IFwMaintenancePriceService fwMaintenancePriceService;

    /**
     * 查询维保价目列表
     */
    @ApiOperation("查询维保价目列表")
    @PreAuthorize("@ss.hasPermi('device:fwMaintenancePrice:list')")
    @GetMapping("/list")
    public TableDataInfo list(FwMaintenancePrice fwMaintenancePrice)
    {
        startPage();
        List<FwMaintenancePrice> list = fwMaintenancePriceService.selectFwMaintenancePriceList(fwMaintenancePrice);
        return getDataTable(list);
    }

    /**
     * 导出维保价目列表
     */
    @ApiOperation("导出维保价目列表")
    @PreAuthorize("@ss.hasPermi('device:fwMaintenancePrice:export')")
    @Log(title = "维保价目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FwMaintenancePrice fwMaintenancePrice)
    {
        List<FwMaintenancePrice> list = fwMaintenancePriceService.selectFwMaintenancePriceList(fwMaintenancePrice);
        ExcelUtil<FwMaintenancePrice> util = new ExcelUtil<FwMaintenancePrice>(FwMaintenancePrice.class);
        util.exportExcel(response, list, "维保价目数据");
    }

    /**
     * 获取维保价目详细信息
     */
    @ApiOperation("获取维保价目详细信息")
    @PreAuthorize("@ss.hasPermi('device:fwMaintenancePrice:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(fwMaintenancePriceService.selectFwMaintenancePriceById(id));
    }

    /**
     * 新增维保价目
     */
    @ApiOperation("新增维保价目")
    @PreAuthorize("@ss.hasPermi('device:fwMaintenancePrice:add')")
    @Log(title = "维保价目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FwMaintenancePrice fwMaintenancePrice)
    {
        return toAjax(fwMaintenancePriceService.insertFwMaintenancePrice(fwMaintenancePrice));
    }

    /**
     * 修改维保价目
     */
    @ApiOperation("修改维保价目")
    @PreAuthorize("@ss.hasPermi('device:fwMaintenancePrice:edit')")
    @Log(title = "维保价目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FwMaintenancePrice fwMaintenancePrice)
    {
        return toAjax(fwMaintenancePriceService.updateFwMaintenancePrice(fwMaintenancePrice));
    }

    /**
     * 删除维保价目
     */
    @ApiOperation("删除维保价目")
    @PreAuthorize("@ss.hasPermi('device:fwMaintenancePrice:remove')")
    @Log(title = "维保价目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(fwMaintenancePriceService.deleteFwMaintenancePriceByIds(ids));
    }
    /**
     * 导入维保价目
     */
    @Log(title = "维保价目", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<FwMaintenancePrice> util = new ExcelUtil<>(FwMaintenancePrice.class);
        List<FwMaintenancePrice> fwMaintenancePriceList = util.importExcel(file.getInputStream());
        String operName = getUsername();
        String message = fwMaintenancePriceService.imporIteminfo(fwMaintenancePriceList, updateSupport, operName);
        return AjaxResult.success(message);
    }
    // 下载模板
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) throws IOException
    {
        ExcelUtil<FwMaintenancePrice> util = new ExcelUtil<>(FwMaintenancePrice.class);
        util.importTemplateExcel(response,"维保价目");
    }
}
